home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Path: ERA.COM!era!spencer
- From: spencer@ERA.COM (Spencer Allain)
- Subject: Re: Hungarian notation
- In-Reply-To: c2a192@ugrad.cs.ubc.ca's message of 21 Jan 1996 10: 02:24 -0800
- Message-ID: <SPENCER.96Jan22113215@zorgon.ERA.COM>
- Sender: news@ERA.COM
- Organization: Engineering Research Associates, Vienna, VA
- References: <30C40F77.53B5@swsbbs.com> <4cvu68$2jb@macaw.cyberport.com>
- <4d21og$iab@news.xmission.com> <4d2ok0$69s@beach.and.nl>
- <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca>
- Date: Mon, 22 Jan 1996 16:32:15 GMT
-
- In article <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca> c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
-
- > Typedef-like constructs are useful in poorly thought-out languages
- > like Modula or Pascal, whose compilers can typically perform
- > typechecks based only on name equivalence. That is to say, if I
- > declare two types that are both integers, the compiler will say that
- > the two types are not equivalent, because it goes only as far as to
- > check the name. This is a cop out which simplifies doing one of the
- > more difficult phases of compiler construction, which is type
- > checking. It has nothing to do with implementing "domains", and
- > everything to do with lazy compiler construction. Real compilers will
- > detect structure equivalence between types so that you don't have to
- > obfuscate your code with confusing type names. To implement domains,
- > just lobotomize the compiler by removing the structure equivalence
- > checking so that size_t and time_t become incompatible types.
-
- Ok. I promised myself I was going to stay out of this thread, but I
- can't let a statement like this go unheeded.
-
- I'm not going to argue about the design of Modula and Pascal, as that
- would be like discussing K&R C. I will note however, that Modula-3 is
- a successor to that lineage and it has true structural equivalence,
- not a named equivalence type checking system like C++.
-
- It is incorrect to say that a 'char' (of size 1 byte on many systems)
- and an 'int' (of size 4 bytes on many systems) is structurally
- equivalent, yet I must be able to compile this without errors:
- (warnings are _not_ errors -- though I get none compiling this anyway)
-
- char a;
- int b;
-
- int main()
- {
- b = -154267 ;
- a = b ;
- return 0 ;
- }
-
- Also, even though structurally equivalent, a C compiler must complain
- that 'theta = beta' is illegal due to incompatible types.
-
- struct {int k;} alpha, beta ;
- struct {int k;} theta ;
-
- int main()
- {
- alpha.k = 1 ;
- beta = alpha ;
- theta = beta ;
- return 0 ;
- }
-
- I know that it sounds as though I'm bashing C, but I'm just trying to
- point out some of the restrictions that cannot be completely lifted
- regardless of how good a compiler you use. Warnings can help, such
- as the one where some C++ compilers warn when you make comparisons
- between signed and unsigned types (which is a senseless comparison,
- but is allowed mostly because there aren't true subtypes, but that
- is another issue).
-
- If you wish to examine more how Modula-3 does its structural
- equivalence, and also how it allows reference and object types to be
- "BRANDED" so as to guaranteed non-equivalence with other structurally
- equivalent but conceptually different types check out:
-
- http://www.research.digital.com/SRC/modula-3/html/home.html
-
- specifically the online definition of the language:
-
- http://www.research.digital.com/SRC/m3defn/html/m3.html
-
- -Spencer
-
- ----------------------------------------------------------------------
- Spencer Allain E-mail: spencer@era.com
- Engineering Research Associates Phone : (703) 734-8800 x1414
- 1595 Spring Hill Road Fax : (703) 827-9411
- Vienna, VA 22182-2235
-
- Modula-3 FAQ http://www.vlsi.polymtl.ca/m3/
- <A HREF=http://www.vlsi.polymtl.ca/m3/>Modula-3 FAQ, etc. </A>
- ----------------------------------------------------------------------
-